<%@page contentType="text/html" import="java.sql.*"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<jsp:useBean id="event" scope="session" class="com.asaga.tools.Event_DBImpl" />
<jsp:useBean id="userProfile" scope="session" class="com.asaga.tools.SystemClient_DBImpl" />
<jsp:useBean id="location" scope="session" class="com.asaga.tools.Location_DBImpl" />
<jsp:useBean id="fontBean" scope="session" class="com.asaga.tools.FontBean" />
<jsp:setProperty name="fontBean" property="*" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<% 
String username = (String)session.getAttribute("username");
if(username==null){
    response.sendRedirect("login.jsp?message=Please log in again.");
}
ResultSet myEvents = userProfile.getAttendingEvents();
ResultSet pastEvents = userProfile.getAttendedEvents();
%>

<html>
    <%@ include file="header.jsp" %>
    <body>
        <div id="container">
            <%@ include file="topNav.jsp" %>
            <%@ include file="leftside.jsp" %>
            <%@ include file="rightside.jsp" %>
            <div id="content">
                <p id="warning"><jsp:getProperty name="userProfile" property="welcomeMsg" />
                </p>
                
                <h4 class="heading">My Event Schedule</h4><br />
                <%if(myEvents == null || !myEvents.next()){%>
                You have no events on your schedule.
                <%}
                else{%>
                <form method="get" action="AutismSiteMasterController">
                    <table class="eventForm">
                        <tr><th></th>
                            <th>Title</th>
                            <th>Location</th>
                            <th>City</th>
                            <th>Start Date</th>
                            <th>Start Time</th>
                            <th>End Time</th>
                        </tr>
                        <% myEvents.beforeFirst(); 
                        while(myEvents.next()){%>
                        <tr>
                            <td class="selectCell">
                                <input type="radio" name="eventId" value="<%=myEvents.getInt("eventID")%>" />
                            </td>
                            <td>
                                <%=myEvents.getString("event_title")%>
                            </td>
                            <td>
                                <%=myEvents.getString("location_title")%>
                            </td>
                            <td>
                                <%=myEvents.getString("city")%>, <%=myEvents.getString("state")%>
                            </td>
                            <td>
                                <%=event.revertDate(myEvents.getDate("startDate"))%>
                            </td>
                            <td>
                                <%=event.revertTime(myEvents.getTime("startTime"))%>
                            </td>
                            <td>
                                <%=event.revertTime(myEvents.getTime("endTime"))%>
                            </td>
                        </tr>
                        
                        <%}%>
                    </table>
                    <table class="eventForm">
                        <tr><td class="buttonCell">
                                <input type="submit" value="View Event" name="action" />
                                <input type ="submit" value="Remove From Calendar" name="action" />
                            </td>
                        </tr>
                    </table>  
                </form>     
                <%}%>
            </div>
            <div id="content">
                <h4 class="heading">Past Events Attended</h4><br />
                <%if(pastEvents == null || !pastEvents.next()){%>
                You have attended no events.
                <%}
                else{
                    pastEvents.beforeFirst();%>
                <form method="get" action="AutismSiteMasterController">
                    <table class="eventForm">
                        <tr><th></th>
                            <th>Title</th>
                            <th>Location</th>
                            <th>City</th>
                            <th>Start Date</th>
                            <th>Start Time</th>
                            <th>End Time</th>
                        </tr>
                        <% while(pastEvents.next()){%>
                        <tr>
                            <td class="selectCell">
                                <input type="radio" name="eventId" value="<%=pastEvents.getInt("eventID")%>" />
                            </td>
                            <td>
                                <%=pastEvents.getString("event_title")%>
                            </td>
                            <td>
                                <%=pastEvents.getString("location_title")%>
                            </td>
                            <td>
                                <%=pastEvents.getString("city")%>, <%=pastEvents.getString("state")%>
                            </td>
                            <td>
                                <%=event.revertDate(pastEvents.getDate("startDate"))%>
                            </td>
                            <td>
                                <%=event.revertTime(pastEvents.getTime("startTime"))%>
                            </td>
                            <td>
                                <%=event.revertTime(pastEvents.getTime("endTime"))%>
                            </td>
                        </tr>
                        
                        <%}%>
                    </table>
                    <table class="eventForm">
                        <tr><td class="buttonCell">
                                <input type="submit" value="Provide Feedback" name="action" />
                                <input type ="submit" value="Remove Past Event" name="action" />
                            </td>
                        </tr>
                    </table>  
                </form>     
                <%}%>
            </div>            
            <%@ include file="footer.html" %>
        </div>        
    </body>
</html>
